package com.example.service;

import com.example.mapper.EchartsMapper;
import com.example.pojo.BarData;
import com.example.pojo.PieData;
import com.example.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EchartsService {
    @Autowired
    private EchartsMapper echartsMapper;

    public Result getBarData(){

        List<BarData> list=echartsMapper.getBarData();
        List<String> nameList=new ArrayList<>();
        List<Integer> countList=new ArrayList<>();

        if (list!=null && list.size()>0){
            for (BarData barData:list) {
                nameList.add(barData.getName());
                countList.add(barData.getCount());
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("level",nameList);
        map.put("count",countList);

        return new Result(200,"操作成功",map);
    }

    public Result getPieData() {
        List<PieData> list=echartsMapper.getPieData();
        return new Result(200,"数据加载成功",list);
    }
}
